﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using HRSystem.Entity;
using HRSystem.Utility;
using HRSystem.DBAccess;
using CrystalDecisions.CrystalReports.Engine;
using System.Xml;
using System.Collections;
using System.Drawing;

namespace HRSystem
{
    public class PageCommon
    {
        public static void Init()
        {
            FileLog.SetErrorFile(PageConst.ERROR_FILENAME);
            FileLog.SetLogFile(PageConst.LOG_FILENAME);
        }

        public static DialogResult ShowMessageByYesNo(string megStr)
        {
            return MessageBox.Show(megStr,PageConst.BELONG_CHINESE_NAME,MessageBoxButtons.YesNo,MessageBoxIcon.Information);
        }

        public static DialogResult ShowMessageByOK(string megStr)
        {
            return MessageBox.Show(megStr,PageConst.BELONG_CHINESE_NAME,MessageBoxButtons.OK,MessageBoxIcon.Information);
        }

        public static void FormatDateTimePickerByYearMonth(DateTimePicker dateTimePicker)
        {
            dateTimePicker.Format = DateTimePickerFormat.Custom;
            dateTimePicker.CustomFormat = "yyyy-MM";
            dateTimePicker.Value = DateTime.Now;
        }

        public static void FormatDateTimePickerByYearMonthDay(DateTimePicker dateTimePicker)
        {
            dateTimePicker.Format = DateTimePickerFormat.Custom;
            dateTimePicker.CustomFormat = "yyyy-MM-dd";
            dateTimePicker.Value = DateTime.Now;
        }

        public static void DisposeForm(Form frm)
        {
            if (frm != null && !frm.IsDisposed)
            {
                try
                {
                    frm.Close();
                    frm.Dispose();
                }
                catch { }
            }
        }

        public static void DisposeReport(ReportClass report)
        {
            if (report != null)
            {
                try
                {
                    report.Close();
                    report.Dispose();
                }
                catch { }
            }
        }

        public static DataGridViewTextBoxColumn BuildColumn(string header,string name,string datafield,bool bVisible)
        {
            DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
            column.HeaderText = header;
            column.Name = name;
            column.DataPropertyName = datafield;
            column.Visible = bVisible;
            column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            return column;
        }

        public static DataGridViewImageColumn BuildImagesColumn(string header,string name,string datafield,bool bVisible,string imageUrl)
        {
            DataGridViewImageColumn column = new DataGridViewImageColumn();
            if (!string.IsNullOrEmpty(imageUrl))
                column.Image = Image.FromFile(imageUrl);
            column.HeaderText = header;
            column.Name = name;
            column.DataPropertyName = datafield;
            column.Visible = bVisible;
            return column;
        }
    }
}
